/**
 * axios
 */
import axios from 'axios';

// let baseUrl = "http://116.62.147.89:8089/";
let baseUrl = "http://localhost:8089/";

//查询全部
export const getBlogAll = param => {

    return axios.get(`${baseUrl}getBlogAll`,{ params : param })
};

//根据id查询
export const getBlogById = param => {
    return axios.get(`${baseUrl}getBlogById`,{params : param});
};

//根据uid查询
export const getBlogByUid = param => {
    return axios.get(`${baseUrl}getBlogByUid`,{params : param});
};

//根据关键字查询
export const getBlogByKeyword = param => {
    return axios.get(`${baseUrl}getBlogByKeyword`,{params : param},{
      xhrFields : {withCredentials: true},
      crossDomain : true,
    });
};

//根据id删除
export const delBlogById = param => {
    return axios.get(`${baseUrl}delBlog`,{params : param});
};


//添加
export const addBlog = param => {
    // xhrFields : {withCredentials: true},
  //         crossDomain : true,
  //         headers:{
  //             'Content-Type': 'application/json'
  //         },
    return axios.post(`${baseUrl}addBlog`,param,
  {headers : {
      'Content-Type': 'application/json'
      },
    xhrFields : {withCredentials: true},
    crossDomain : true,
    }).then(res => res.data);
};

//编辑
export const editBlog = param => {

    return axios.post(`${baseUrl}editBlog`,param,
    {headers : {
        'Content-Type': 'application/json'
    },
      xhrFields : {withCredentials: true},
      crossDomain : true,
    }).then(res => res.data);
};



//用户

//注册
export const register = param => {
  return axios.post(`${baseUrl}user/register`,param,
    {headers : {
        'Content-Type': 'application/json'
      }}).then(res => res.data);
};


//登录
export const login = param => {
  return axios.post(`${baseUrl}user/login`,param,
  {
      xhrFields : {withCredentials: true},
      crossDomain : true,
      headers:{
        'Content-Type': 'application/json'
      },
    }).then(res => res.data);
};

//重置密码
//resetPassword
export const resetPassword = param => {
  return axios.get(`${baseUrl}user/resetPassword`,{params : param});
};

//修改密码
export const updatePassword = param => {
  return axios.post(`${baseUrl}user/updatePassword`,param,
    {
      xhrFields : {withCredentials: true},
      crossDomain : true,
      headers:{
        'Content-Type': 'application/json'
      },
    }).then(res => res.data);
};

//退出登录
export const logout = param => {
  return axios.get(`${baseUrl}user/logout`,{params : param});
};
// //添加
// export const addBlog = param => {
//     // axios.headers['Content-Type'] = 'application/x-www-form-urlencoded'
//     axios.headers = {
//         'Content-Type': 'application/x-www-form-urlencoded'
//     };
//     return axios.post(`${baseUrl}addBlog`,param,
//     {headers : {
//         'Content-Type': 'application/json'
//     }}).then(res => res.data);
// }


export const uploadImg = param => {
    return axios.post(`${baseUrl}upload`,param).then(res => res.data);
};




// post
//  var loginParams = { username: this.ruleForm2.account, password: this.ruleForm2.checkPass };
// requestLogin(loginParams).then(data => {
//     this.logining = false;
//     //NProgress.done();
//     let { msg, code, user } = data;
//     if (code !== 200) {
//       this.$message({
//         message: msg,
//         type: 'error'
//       });
//     } else {
//       sessionStorage.setItem('user', JSON.stringify(user));
//       this.$router.push({ path: '/table' });
//     }
//   });
